package com.tjetc.adminmanage;

import com.tjetc.domian.Propertyservice;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.ServiceService;
import com.tjetc.view.AdminMainView;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

// 物业服务管理
public class ServiceManageView {
    private static Scanner scanner = new Scanner(System.in);
    private static ServiceService serviceService = ClientProxy.getProxyInstance(ServiceService.class);
    public void start() {
        while (true) {
            System.out.println("物业服务管理菜单");
            System.out.println("1.查询物业服务");
            System.out.println("2.添加物业服务");
            System.out.println("3.修改物业服务");
            System.out.println("4.删除物业服务");
            System.out.println("0.返回上一级");
            int i = scanner.nextInt();
            switch (i) {
                case 1:
                    list();
                    break;
                case 2:
                    add();
                    break;
                case 3:
                   updata();
                    break;
                case 4:
                    del();
                    break;
                case 0:
                    new AdminMainView().start();
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }

    }

    private void del() {
        System.out.println("删除物业服务");
        System.out.println("输入服务id");
        int serviceid = scanner.nextInt();
        Result result = serviceService.del(serviceid);
        System.out.println(result.getMsg());
    }

    private void updata() {
        System.out.println("修改物业服务");
        System.out.println("输入服务id");
        int serviceid = scanner.nextInt();
        System.out.println("输入更改后的服务名称");
        String servicename = scanner.next();
        System.out.println("输入更改后的服务类型");
        String servicetype = scanner.next();
        System.out.println("输入更改后的服务频率");
        String frequency = scanner.next();
        System.out.println("输入更改后的服务提供商");
        String provider = scanner.next();
        Propertyservice propertyservice = new Propertyservice();
        propertyservice.setServiceid(serviceid);
        propertyservice.setServicename(servicename);
        propertyservice.setServicetype(servicetype);
        propertyservice.setFrequency(frequency);
        propertyservice.setProvider(provider);
         Result  result = serviceService.update(propertyservice);
         System.out.println(result.getMsg());
    }

    private void add() {
        System.out.println("添加物业服务");
        System.out.println("输入服务名称");
        String servicename = scanner.next();
        System.out.println("输入服务类型");
        String servicetype = scanner.next();
        System.out.println("输入服务频率");
        String frequency = scanner.next();
        System.out.println("输入服务提供商");
        String provider = scanner.next();
        Propertyservice propertyservice = new Propertyservice();
        propertyservice.setServicename(servicename);
        propertyservice.setServicetype(servicetype);
        propertyservice.setFrequency(frequency);
        propertyservice.setProvider(provider);
        serviceService.add(propertyservice);
        Result  result = serviceService.update(propertyservice);
        System.out.println(result.getMsg());

    }

    private void list() {
      List<Propertyservice> list = serviceService.select();
      for (Propertyservice propertyservice : list) {
          System.out.println(propertyservice);
      }
    }
}
